/**
 * @created by kongqf on 2019-12-5 09:36:02
 * @updated by
 * @description jobFlowGraph
 */
// 注意js引用顺序
define([
  './pages/use/apps/jobManager/jobFlowGraph/jobFlowGraph.css',
  './libs/mxgraph/libs/init.js',
  './libs/mxgraph/libs/sanitizer.min.js',
  './libs/mxgraph/libs/editorUi.js',
  './libs/mxgraph/libs/editor.js',
  './libs/mxgraph/libs/sidebar.js',
  './libs/mxgraph/libs/graph.js',
  './libs/mxgraph/libs/format.js',
  './libs/mxgraph/libs/shapes.js',
  './libs/mxgraph/libs/actions.js',
  './libs/mxgraph/libs/menus.js',
  './libs/mxgraph/libs/toolbar.js',
  './libs/mxgraph/libs/dialogs.js',
  './custom/widgets/js/YuWorkflow.js',
  './pages/use/monitors/taskMonitor/taskMonitorGraph/taskMonitorGraph.css'
],function (require, exports) {
  /**
   * 页面加载完成时触发
   * @param hashCode 路由ID
   * @param data 传递数据对象
   * @param cite 页面站点信息
   */
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('USE_TASK_JOB_TYPE,USE_EVT_REL_TYPE,USE_FIXED_TIME_RANGE,USE_FIXED_TIME_F,USE_JOB_RUN_STATE');
    var size = yufp.frame.size();
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        return {
          width: size.width,
          timeOptions: [{key: -1, value:'不自动刷新'},{key: 10, value:'10秒'},{key: 20, value:'20秒'},{key: 30, value:'30秒'},{key: 60, value:'60秒'}],
          frequencyOptions: [],
          timerDelay: 60,
          dialogVisible:false,
          currentTime: yufp.util.dateFormat(new Date(), '{y}-{m}-{d} {h}:{i}:{s}'),
          dialogTitle: '',
          formDisabled: false,
          circulationFormData:{},
          workBaseFormData:{},
          workExecFormData: {},
          workAdditionalFormData: {},
          workData: {},
          timer: null,
          system: '',
          filterText: '',
          options: [{
            key: 'Y',
            value: '是'
          },{
            key: 'N',
            value: '否'
          }],
          nodetype: '',
          sidebarItems: [],
          tableData1: [],
          stepValue: '',//步长值
          condTypeValue:'运行',// 状态值
          workFlowTabsActiveName: 'first',
          workFlowTabs:[],
          workFlowData: null,
          stepValueShow:false,//显示设置步长输入框
/*          stepValue:'', */
          flowJobList:[],// 作业节点数组
          preValueFormdata: {},//预置返回值表单对象
          cellTem:{},// 当前点击的节点对象
          workflowArr: [],
          activeName: '',
          islock: false,
          baseFormData: {},
          wftParList: [],
          refLogFormData: {},
          useEventLogList: [],
          visible: false,
          agentIds: [],
          logText: '',
          isHistory: false,
          requestUrl: '',
          notAutoLayout: false,
          requestArr: [],
          showModifyRetValue: false,
          modifyRetValue: {returnValue: 0}, // 强制成功, 修改返回值
          successMaxRetValue: 0,
          customKey: null,
          tabsActiveName: '0',
          jobStateObj: {
            'C': '已崩溃',
            'E': '错误',
            'F': '失败',
            'I': '被中断',
            'O': '完成',
            'Q': '排队中',
            'S': '成功',
            'U': '未知',
            'W': '未执行',
            'X': '执行中',
          },
          newFlag: '1',
          scale: 6,
          anyscLoading: null,
          showWorkBaseForm: false,
          showTabsTitle: false,
          isRefreshing: false,
          isShow: false 
        };
      },
      computed:{
        runModeValue:function(){
          var a = 'RUNNING';
          var b = 'DEBUG';
           var c = this.workBaseFormData.runMode === 'RUNNING'?b:a
          return c;
        },
        height: function () {
          var height = this.showTabsTitle ? size.height - 172 : size.height - 133;
          return height;
        }
        //stepValue:function(){
        //  var a = this.workBaseFormData.stepValue?this.workBaseFormData.stepValue:'';
        //  return a;
        //},
      },
      created: function () {
        var _this = this;
        var groupName = data.groupName;
        var taskName = data.taskName;
        var workName = data.isHistory ? data.taskName : data.groupName;
        _this.customKey = data.customKey;
        _this.queryWftAgtList();
        _this.anyscLoading = this.$loading({ fullscreen: true })
        if (data.isHistory) {
          _this.isHistory = true;
        }
        if(data.isLock||data.isHistory) {
          _this.islock = true;
          _this.isShow = true;
        }
        if(!data.runFnButton) {
          _this.isShow = true;
          _this.isHistory = true;
          _this.stepValueShow = false;
        }
        if (data.jobState === 'S'||data.isHistory) {
          this.requestUrl = '/monitor/taskMonitorHis/queryFlowChart';
        } else {
          this.requestUrl = '/monitor/taskMonitor/queryFlowChart';
        }
        _this.requestArr.push({
          coreId: data.coreId||data.wftId,
          cycleNo: data.cycleNo,
          groupCode: data.groupCode,
          appCode: data.appCode
        });
        yufp.service.request({
          url: backend.useService + _this.requestUrl,
          method: 'get',
          data: _this.requestArr[+_this.activeName],
          callback: function (code, message, response) {
            if(response && response.data) {
              _this.notAutoLayout = response.data.newFlag == 1;
              if (data.jobState === 'S'||data.isHistory) { // 如果是历史任务, 则节点的hisFlag都设置为1
                response.data.flowJobInfoList.forEach(function(cell) {
                  cell.hisFlag = '1';
                })
              }
              _this.workflowArr.push(yufp.clone({workName: workName, groupName: groupName, taskName: taskName}, response.data));
            }
          }
        });
      },
      mounted(){
        // 获取应用系统下拉列表数据
        this.getFrequencyOptions();
      },
      methods: {
        /**
         * 加载集群代理名称
         */
        queryWftAgtList:function(){
          var _this = this;
          var paramObj = {};
          paramObj.appCode = data.appCode;
          yufp.service.request({
            method: 'GET',
            url:  backend.useService + "/plats/apps/queryWftAgtList",
            data: paramObj,
            async:false,
            callback: function (code, message, response) {
              if (response.code!=0) {
                isOk = false;
                _this.$message(response.message);
              } else {
                _this.agentIds.splice(0);
                _this.agentIds.push({key:" ",value:"虚拟代理"});
                for(let i=0;i<response.data.length;i++){
                    _this.agentIds.push({key:response.data[i].agentCode,value:response.data[i].agentName});
                }
              }
            }
          });
        },
        // 获取应用系统下拉列表数据
        getFrequencyOptions:function(){
          var _this = this;
          _this.frequencyOptions.splice(0);
          yufp.service.request({
            url: backend.useService + '/plats/apps/getWftAppList',
            method: 'get',
            callback: function (code, message, response) {
              response.data.forEach(item=>{
                var obj={};
                obj.key=item.appCode;
                obj.value=item.appName;
                _this.frequencyOptions.push(obj);
              })
            }
          });
        },
        // 获取步长信息
        getStepValueFn:function(){
          var _this = this;
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/getDebugRunStep',
            method: 'get',
            data: {
              appCode: data.appCode,
              cycleNo: data.cycleNo,
            },
            callback: function (code, message, response) {
            }
          });
        },
        // 设置步长信息
        setStepValueFn:function(){
          var _this = this;
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/setDebugRunStep',
            method: 'get',
            data: {
              appCode: data.appCode,
              cycleNo: data.cycleNo,
              stepValue: _this.stepValue
            },
            callback: function (code, message, response) {
              if(code === 0){
                _this.btnRefreshWorkFlowFn();
              }
            }
          });
        },
        // 切换 调试 运行 状态
        changecondTypeFn:function(){
          var _this = this;
          // 调试模式显示设置步长
          _this.timeOptions.splice(0);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/reverseRunMode',
            method: 'get',
            data:{appCode:data.appCode,cycleNo:data.cycleNo},
            callback: function (code, message, response) {
              if(response.code === 0){
                // _this.initGraph(_this.activeName);
                _this.refreshGraph(_this.activeName);
                _this.$message({message:response.message,type:'success'});
                if(_this.workBaseFormData.runMode === 'DEBUG'){
                  _this.stepValueShow = true;
                }
                else{
                  _this.stepValueShow = false;
                }
              }else{
                // 操作WFT失败
                _this.$message({message:response.message,type:'warning'});
              }
            }
          });
        },
        addWorkFlow: function (index, data) {
          var _this = this;
          if (!_this.$refs.refWorkflow[index]) {
            return;
          }
          _this.newFlag = data.newFlag;
          var notSetEdgeAnchorPoint = _this.newFlag == '1';
          _this.$refs.refWorkflow[index].clearGraph();
          var vertexList = _this.$refs.refWorkflow[index].addVertexList(null, _this.data2CellData(data['flowJobInfoList'], data));
          yufp.clone(data['flowJobInfoList'],_this.flowJobList);//作业节点列表
          _this.$refs.refWorkflow[index].addEdgeList(null, _this.data2EdgeData(data['flowLinksInfoList']), notSetEdgeAnchorPoint, vertexList);
          yufp.clone(data,_this.workBaseFormData);
          _this.system = data.appCode;
          _this.stepValue= _this.workBaseFormData.stepValue;
          if (_this.workBaseFormData.runMode === 'DEBUG') {
            _this.stepValueShow = true;
          } else {
            _this.stepValueShow = false;
          }
          _this.$refs.refWorkflow[index].updateWorkStates([], _this.data2CellData(data['flowJobInfoList'], data));
          _this.$refs.refWorkflow[index].graphComplete();
          _this.$refs.refWorkflow[index].updateEdgeStyle();
          _this.anyscLoading && _this.anyscLoading.close();
        },
        initGraph:function(index){
          var _this = this;
          // 先激活当前页签，并把节点生成放进nextTick中，不然mxgraph布局时获取container宽高为0
          _this.activeName = index + '';
          _this.$nextTick(function () {
            if (_this.workflowArr[index] && (_this.workflowArr[index].taskName || _this.workflowArr[index].groupName)) {
              _this.addWorkFlow(index, _this.workflowArr[index]);
              return;
            }
          });
        },
        refreshGraph: function(index) {
          var _this = this;
          // 先激活当前页签，并把节点生成放进nextTick中，不然mxgraph布局时获取container宽高为0
          _this.activeName = index + '';
          _this.$nextTick(function () {
            if (_this.workflowArr[index] && (_this.workflowArr[index].taskName || _this.workflowArr[index].groupName)) {
              _this.refreshWorkFlow(index, _this.workflowArr[index]);
              return;
            }
          });
        },
        refreshWorkFlow: function(index, data) {
          var _this = this;
          if (!_this.$refs.refWorkflow[index]) {
            return;
          }
          var cellData = _this.data2CellData(data['flowJobInfoList'], data);
          var edgeData = _this.data2EdgeData(data['flowLinksInfoList']);
          var cells = _this.$refs.refWorkflow[index].graph.getModel().cells;
          for(var k in cells) {
            if(cells[k].edge) {
              edgeData.forEach(function(edge) {
                if (cells[k].id === edge.id) {
                  cells[k].data = edge.data;
                }
              })
            } else if (cells[k].vertex) {
              cellData.forEach(function(vertex) {
                if (cells[k].id === vertex.id) {
                  cells[k].data = vertex.data;
                }
              })
            }
          }
          yufp.clone(data['flowJobInfoList'],_this.flowJobList); // 作业节点列表
          yufp.clone(data,_this.workBaseFormData);
          _this.system = data.appCode;
          _this.stepValue= _this.workBaseFormData.stepValue;
          if (_this.workBaseFormData.runMode === 'DEBUG') {
            _this.stepValueShow = true;
          } else {
            _this.stepValueShow = false;
          }
          _this.$refs.refWorkflow[index].updateWorkStates([], cellData);
          _this.$refs.refWorkflow[index].updateEdgeStyle();
        },
        getData2Form: function(data){
          this.workBaseFormData = yufp.extend(true, data, {
           appCode: '',
            typeCode: '',
            actionCode: '',
            actionName: '',
            maxRetry: '',
            actionPrior: '',
            redcheckbox: '',
            redselect: '',
            intrFlag: '',
            multiFlag: '',
            remark: ''
          });
          console.log('表单数据', this.workBaseFormData );
        },
        /**
         * 将接口数据转换成graph节点数据
         */
        data2CellData: function(data, flowData){
          var _this = this;
          var cells = [];
          var baseY = 160;
          var size = 50;
          var maxY = this.getCellsMaxY(flowData);
          if(data && data.length>0){
            baseY = data[0].positionY
          }
          cells.push({
            id: '.<@START@>.',
            nodetype: '.<@START@>.',
            value: '',
            x: data.length > 0 ? flowData.posBeginX * _this.scale : -100,
            y: _this.newFlag == '1' ? -(flowData.posBeginY - maxY) * _this.scale : data.length > 0 ? -flowData.posBeginY *  _this.scale : baseY,
            width: size,
            height: size,
            style: 'image;image=libs/mxgraph/images/workflow/wstart.png;',
            relative: false,
            data: {}
          });
          data.forEach(function(item, index){
            cells.push({
              id: item.actionCode,
              nodetype: item.typeCode,
              value: item.actionName,
              x: item.positionX * _this.scale,
              y: _this.newFlag == '1' ? -(item.positionY - maxY) * _this.scale : -item.positionY * _this.scale,
              width: size,
              height: size,
              style: 'image;image=libs/mxgraph/images/workflow/'+item.typeCode+'.png;',
              relative: false,
              data: item
            })
          })
          cells.push({
            id: '.<@END@>.',
            nodetype: '.<@END@>.',
            value: '',
            x: data.length > 0 ? flowData.posEndX * _this.scale : 400,
            y: _this.newFlag == '1' ? -(flowData.posEndY - maxY) * _this.scale : data.length > 0 ? -flowData.posEndY * _this.scale : baseY,
            width: size,
            height: size,
            style: 'image;image=libs/mxgraph/images/workflow/wend.png;',
            relative: false,
            data: {}
          });
          return cells;
        },
        data2EdgeData: function(data){
          var cells = [];
          data.forEach(function(item){
            cells.push({
              id: (item.condAction.trim() || '.<@START@>.') + '-' + (item.actionCode.trim() || '.<@END@>.'),
              value: '',
              path: item.flowPath,
              style: item.drawInfo || '',
              data: item,
              source: item.condAction.trim() || '.<@START@>.',
              target: item.actionCode.trim() || '.<@END@>.'
            })
          })
          return cells;
        },
        getCellsMaxY: function(flowData) {
          var yArr = [flowData.posBeginY, flowData.posEndY];
          flowData.flowJobInfoList.forEach(function(item) {
            yArr.push(item.positionY);
          });
          return Math.max.apply(Math, yArr);
        },
        // 根据ID获取作业节点
        getJobObj:function(id){
          var obj ={};
          this.flowJobList.forEach(item=>{
            if(item.actionCode === id){
              yufp.clone(item,obj)
            }
          })
          return obj;

        },
        // 中断作业流
        interruptTask:function(id){
          var _this = this;
          var job = _this.getJobObj(id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/interruptTask',
            method: 'get',
            data: {
              appCode: job.appCode,
              cycleNo: job.cycleNo,
              sequence:job.sequence
            },
            callback: function (code, message, response) {
              if (code === 0) {
                _this.$message({message: response.message, type:'success'});
                _this.btnRefreshWorkFlowFn();
              } else {
                _this.$message({message: response.message, type:'warning'});
              }
            }
          });
        },
        // 重做作业流
        redoRunTask:function(id){
          var _this = this;
          var obj =_this.getJobObj(id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/redoRunTask',
            method: 'get',
            data: {
              appCode: obj.appCode,
              cycleNo: obj.cycleNo,
              actionCode:obj.actionCode,
              sequence:obj.sequence
            },
            callback: function (code, message, response) {
              if (code === 0) {
                _this.$message({message: response.message, type:'success'});
                _this.btnRefreshWorkFlowFn();
              } else {
                _this.$message({message: response.message, type:'warning'});
              }
            }
          });
        },
        // 设置返回值
        setPreValue:function(){
          var _this = this;
          var obj = _this.getJobObj(_this.cellTem.id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/setPreValue',
            method: 'get',
            data: {
              appCode: obj.appCode,
              cycleNo: obj.cycleNo,
              groupCode: obj.groupCode,
              actionCode: obj.actionCode,
              retValue: _this.preValueFormdata.returnValue
            },
            callback: function (code, message, response) {
              if (code === 0) {
                _this.$message({message: response.message, type:'success'});
                _this.cellTem.data.retValue = _this.preValueFormdata.returnValue;
                _this.btnRefreshWorkFlowFn();
                _this.dialogVisible = false;
              } else {
                _this.$message({message: response.message, type:'warning'});
              }
            }
          });
        },
        setModifyRetValuee: function() {
          this.successMaxRetValue = this.cellTem.data.retValue || 0;
          if (this.modifyRetValue.returnValue >= 0 && this.modifyRetValue.returnValue <= 255 && this.modifyRetValue.returnValue % 1 === 0) {
            this.forceJobSuccess();
          } else {
            this.$message({message: '请输入0到255之间的整数', type:'warning'});
          }
        },
        // 作业失败后强制作业成功
        forceJobSuccess:function(){
          var _this = this;
          var obj = this.getJobObj(_this.cellTem.id);
          _this.showModifyRetValue = false;
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/forceJobSuccess',
            method: 'get',
            data: {
              appCode: obj.appCode,
              cycleNo: obj.cycleNo,
              sequence:obj.sequence,
              retValue: _this.modifyRetValue.returnValue
            },
            callback: function (code, message, response) {
              if (response.code === 0) {
                _this.$message({message:response.message, type:'success'});
                _this.btnUpdateWorkFlowFn();
              } else { 
                _this.$message({message:response.message, type:'warning'});
              }
            }
          });
        },
        // 取消预设置设置返回值
        unsetPreValue:function(id){
          var _this = this;
          var obj = _this.getJobObj(id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/unsetPreValue',
            method: 'get',
            data: {
              appCode: obj.appCode,
              cycleNo: obj.cycleNo,
              groupCode:obj.groupCode,
              actionCode:obj.actionCode
            },
            callback: function (code, message, response) {
              if (code===0) {
                _this.$message({message:response.message, type:'success'});
                _this.cellTem.data.retValue = null;
                _this.btnRefreshWorkFlowFn();
              } else {
                _this.$message({message:response.message, type:'warning'});
              }
            }
          });
        },
        // 启动调试
        debugJobOn:function(id){
          var _this = this;
          var job = _this.getJobObj(id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/debugJobOn',
            method: 'get',
            data: {
              appCode: job.appCode,
              cycleNo: job.cycleNo,
              actionCode:job.actionCode,
              groupCode:job.groupCode
            },
            callback: function (code, message, response) {
              if (code === 0) {
                _this.$message({message:response.message, type:'success'});
                _this.cellTem.data.debug = true;
                _this.btnRefreshWorkFlowFn();
              } else {
                _this.$message({message:response.message, type:'warning'});
              }
            }
          });
        },
        // 取消调试
        debugJobOff:function(id){
          var _this = this;
          var job = _this.getJobObj(id);
          yufp.service.request({
            url: backend.useService + '/monitor/taskMonitor/debugJobOff',
            method: 'get',
            data: {
              appCode: job.appCode,
              cycleNo: job.cycleNo,
              actionCode:job.actionCode,
              groupCode:job.groupCode
            },
            callback: function (code, message, response) {
              if (code === 0) {
                _this.$message({message:response.message, type:'success'});
                _this.cellTem.data.debug = false;
                _this.btnRefreshWorkFlowFn();
              } else {
                _this.$message({message:response.message, type:'warning'});
              }
            }
          });
        },
        overlayclickFn: function(overlay,cell){
          //作业状态  作业操作的逻辑控制
          // typecode = "+" typecode = " "的作业不能做任何操作 
          // todo 作业操作可能有延迟
          // 运行中：可强行中断作业
          // 等待中：可添加取消断点，设置取消预置值
          // 已失败：可强制成功作业，重做作业
          // 被中断：可强制成功作业，重做作业
          var _this = this;
          _this.cellTem = cell;
          if(overlay.type === 'redo'){
            _this.redoRunTask(cell.id);
          } else if(overlay.type === 'interrupt_work') {
            _this.interruptTask(cell.id);
          } else if(overlay.type === 'add_threshold') {
            _this.dialogVisible = true;
          } else if (overlay.type === 'force_success') {
            _this.showModifyRetValue = true;
          } else if(overlay.type === 'remove_threshold') {
            _this.unsetPreValue(cell.id);
          } else if(overlay.type === 'add_breakpoint') {
            _this.debugJobOn(cell.id);
          } else if(overlay.type === 'remove_breakpoint') {
            _this.debugJobOff(cell.id);
          }
        },
        celldblclickFn: function(evt){
          // 重新打开节点页面
          var  _this = this;
          _this.tabsActiveName = '0';
          if (evt.edge) {
            return;
          }
          if (evt.data.nodetype !== '+') {
            var requestUrl = (data.jobState === 'S'||data.isHistory) ? '/monitor/taskMonitorHis/queryFlowJobDetail' : '/monitor/taskMonitor/flowJobDetail'
            // 弹窗
            _this.visible = true;
            yufp.service.request({
              url: backend.useService + requestUrl,
              method: 'get',
              data: {
                coreId: evt.data.coreId,
                sequence: evt.data.sequence,
                cycleNo: evt.data.cycleNo,
                actionCode:evt.data.actionCode,
                groupCode:evt.data.groupCode,
                appCode: evt.data.appCode,
                repeatNo: evt.data.repeatNo,
                cycleTime: _this.workBaseFormData.cyclePnt
              },
              callback: function (code, message, response) {
                if(response&&response.data){
                  _this.$nextTick(function () {
                    var jobState = response.data.jobState;
                    _this.$refs.refBaseForm.resetFields();
                    _this.wftParList.splice(0);
                    _this.useEventLogList.splice(0);
                    _this.logText = '';
                    yufp.clone(response.data, _this.baseFormData);
                    _this.baseFormData.jobStateStr = jobState in _this.jobStateObj ? _this.jobStateObj[jobState] : jobState;
                    _this.logText = response.data.logText;
                    _this.wftParList = yufp.clone(response.data.wftParList, []);
                    _this.useEventLogList = yufp.clone(response.data.useEventLogList, []);
                  });
                } else {
                  _this.$message({message:response.message, type:'warning'});
                }
              }
            });
          } else {
            var requestData = {
              coreId: evt.data.coreId ,
              cycleNo: evt.data.cycleNo,
              groupCode: evt.data.actionExec,
              appCode: evt.data.actionLoc
            };
            yufp.service.request({
              url: backend.useService + _this.requestUrl,
              method: 'get',
              data: requestData,
              callback: function (code, message, response) {
                if(response && response.data) {
                  for (var i = 0; i < _this.workflowArr.length; i++) {
                    if (_this.workflowArr[i].workName === evt.data.actionName) {
                      _this.activeName = i + '';
                      return;
                    }
                  }
                  _this.workflowArr.push(yufp.clone({workName: evt.data.actionName + '-' + evt.data.actionExec}, response.data));
                  _this.requestArr.push(requestData);
                }
              }
            });
          }
          // evt.stopPropagation();
        },
        frequencyChangeFn:function(){
          this.setRefreshTimer();
        },
        setRefreshTimer: function(){
          var _this = this;
          _this.timer && window.clearInterval(_this.timer);
          if (_this.timerDelay > 0) {
            _this.timer = setInterval(function(){
              _this.btnRefreshWorkFlowFn();
            }, parseInt(_this.timerDelay) * 1000)
          }
        },
        btnRefreshWorkFlowFn:function(){
          if (!this.isRefreshing) {
            this.btnUpdateWorkFlowFn();
            this.isRefreshing = true;
          }
        },
        btnUpdateWorkFlowFn: function() {
          var _this = this;
          yufp.service.request({
            url: backend.useService + _this.requestUrl,
            method: 'get',
            data: _this.requestArr[+_this.activeName],
            callback: function (code, message, response) {
              var currentTab = yufp.frame.getTab();
              if(response && response.data) {
                _this.$set(_this.workflowArr, +_this.activeName, yufp.clone(response.data, _this.workflowArr[+_this.activeName]));
                _this.$nextTick(function() {
                  // _this.initGraph(_this.activeName);
                  _this.refreshGraph(_this.activeName);
                });
                _this.currentTime = yufp.util.dateFormat(new Date(), '{y}-{m}-{d} {h}:{i}:{s}');
                if (_this.customKey === currentTab.menuId) {
                  _this.$message('刷新成功');
                }
              } else if (response.data === null) { // 任务运行已完成
                if (_this.customKey === currentTab.menuId) {
                  _this.$alert('任务已完成', '提示', {
                    confirmButtonText: '确定',
                    callback: function (action) {
                      yufp.frame.removeTab(currentTab.id);
                      yufp.frame.reloadTaskMonitorData();
                    }
                  });
                }
              }
              _this.isRefreshing = false;
            }
          });
        },
        tabRemove: function(tabIndex) {
          this.workflowArr.splice(tabIndex, 1);
          this.activeName = tabIndex - 1 + '';
        },
        setAllPreValue: function() {
          var _this = this;
          _this.$confirm('确认将所有作业预置返回值设置为0?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            callback: function (action) {
              if (action === 'confirm') {
                var obj = _this.flowJobList[0];
                yufp.service.request({
                  url: backend.useService + '/monitor/taskMonitor/setPreValue',
                  method: 'get',
                  data: {
                    appCode: obj.appCode,
                    cycleNo: obj.cycleNo,
                    groupCode: obj.groupCode,
                    retValue: 0
                  },
                  callback: function (code, message, response) {
                    if (code === 0) {
                      _this.$message({message: response.message, type:'success'});
                      _this.btnRefreshWorkFlowFn();
                    } else {
                      _this.$message({message: response.message, type:'warning'});
                    }
                  }
                });
              }
            }
          });
        },
        cancelAllPreValue: function() {
          var _this = this;
          _this.$confirm('确认取消所有作业预置返回值?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            callback: function (action) {
              if (action === 'confirm') {
                var obj = _this.flowJobList[0];
                yufp.service.request({
                  url: backend.useService + '/monitor/taskMonitor/unsetPreValue',
                  method: 'get',
                  data: {
                    appCode: obj.appCode,
                    cycleNo: obj.cycleNo,
                    groupCode: obj.groupCode
                  },
                  callback: function (code, message, response) {
                    if (code===0) {
                      _this.$message({message:response.message, type:'success'});
                      _this.btnRefreshWorkFlowFn();
                    } else {
                      _this.$message({message:response.message, type:'warning'});
                    }
                  }
                });
              }
            }
          });
        },
        autoLayout: function() {
          this.$refs.refWorkflow[this.activeName].layout();
          this.btnRefreshWorkFlowFn();
        }
      },
/*      computed:{
        runModeValue:function(){
          var a = 'RUNNING';
          var b = 'DEBUG';
           var c = this.workBaseFormData.runMode === 'RUNNING'?b:a
          return c;
        } 
      //   stepValue:function(){
      //     var a = this.workBaseFormData.stepValue?this.workBaseFormData.stepValue:'';
      // return a;

      //   },
      }*/
    });
  };

  /**
   * 页面传递消息处理
   * @param type 消息类型
   * @param message 消息内容
   */
  exports.onmessage = function (type, message) {
  };

  /**
   * 页面销毁时触发destroy方法
   * @param id 路由ID
   * @param cite 页面站点信息
   */
  exports.destroy = function (id, cite) {
    var _this = this;
    _this.timer && window.clearTimeout(_this.timer);
  };
});
